package ch.ethz.fcl.metrobuzz.render.techniques.circos.version4;

import javax.vecmath.Vector2d;

import ch.ethz.fcl.metrobuzz.render.techniques.arrow.Arrow;
import ch.ethz.fcl.metrobuzz.render.techniques.circos.CircosMatrix;
import ch.ethz.fcl.metrobuzz.render.techniques.circos.version3.CircosDiagram3;
import ch.ethz.fcl.metrobuzz.spatialindex.object2d.Point2D;
import ch.ethz.fcl.metrofont.MetroFont;

/**
 * 
 * @author Zeng Wei
 * @email zeng@arch.ethz.ch
 * 
 *        Compare with version 3, draw arrows at the end of ribbons
 */
public class CircosDiagram4 extends CircosDiagram3 {
	public CircosDiagram4(Point2D center, float radius, CircosMatrix data) {
		super(center, radius, data);
	}

	public void render(MetroFont fm) {
		super.render(fm);
		renderArrow();
	}

	// render arrows at the end of ribbons
	protected void renderArrow() {
		for (int i = 0; i < data.size(); i++) {
			for (int j = 0; j < data.size(); j++) {
				if (i != j) {
					float pixels = proj.getScreenDistance(incomingStartPoints[i][j],
							incomingEndPoints[i][j]);
					if (pixels > 10) {
						Point2D head = incomingStartPoints[i][j].getPointAt(
								incomingEndPoints[i][j], 0.5f);
						Vector2d dir;
						if (j != 0)
							dir = new Vector2d(head.getX() - center.getX(),
									head.getY() - center.getY());
						else
							dir = new Vector2d(-head.getX() + center.getX(),
									-head.getY() + center.getY());

						float width = incomingStartPoints[i][j]
								.distance(incomingEndPoints[i][j]) / 1.2f;

						Arrow.generateDefaultArrow(head, dir, width);
					}
				}
			}
		}

	}
}
